﻿#include "widget2.h"
#include "ui_widget2.h"
#include "qcustomcalendarwidget.h"
#include "common.h"
#include <QDebug>
#include <QPainter>

Widget2::Widget2(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget2)
{
    ui->setupUi(this);
    QCustomCalendarWidget* calendarWidget = new QCustomCalendarWidget(this);
    calendarWidget->setMode(1);
    ui->dateEdit->setDisplayFormat("yyyy/MM");
    ui->dateEdit->setCalendarPopup(true);  // 日历弹出
    ui->dateEdit->setCalendarWidget(calendarWidget);
    ui->dateEdit->setMaximumDate(QDate::currentDate());
    //ui->dateEdit->setFixedSize(150, 26);
    ui->dateEdit->setContextMenuPolicy(Qt::NoContextMenu);
    ui->dateEdit->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

    calendarWidget->setSelectionMode(QCalendarWidget::NoSelection);
    calendarWidget->disconnect(SIGNAL(selectionChanged()));
    calendarWidget->disconnect(SIGNAL(clicked(QDate)));

    connect(calendarWidget, &QCustomCalendarWidget::signalSetCalendarTime, [this](const QDate& data){
        ui->dateEdit->setDate(data);
    });

    QCustomCalendarWidget* calendarWidget2 = new QCustomCalendarWidget(this);
    ui->dateEdit_2->setDate(QDate::currentDate());
    ui->dateEdit_2->setDisplayFormat("yyyy/MM/dd");
    ui->dateEdit_2->setCalendarPopup(true);  // 日历弹出
    ui->dateEdit_2->setCalendarWidget(calendarWidget2);
    ui->dateEdit_2->setMaximumDate(QDate::currentDate().addDays(365));
    //ui->dateEdit_2->setFixedSize(150, 26);
    ui->dateEdit_2->setContextMenuPolicy(Qt::NoContextMenu);
    ui->dateEdit_2->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

    calendarWidget2->disconnect(SIGNAL(selectionChanged()));
    calendarWidget2->disconnect(SIGNAL(clicked(QDate)));

    connect(calendarWidget2, &QCustomCalendarWidget::signalSetCalendarTime, [this](const QDate& data){
        ui->dateEdit_2->setDate(data);
    });

    ui->comboBox_3->setEditable(true);
    ui->comboBox_4->setEditable(true);
    for(auto item : zhibu)
    {
        ui->comboBox_3->addItem(item.first);
    }

    // ui->btnQX->setVisible(false);
    connect(ui->comboBox_3,SIGNAL(currentIndexChanged(int )),this,SLOT(SlotCurrentIndexChange(int )));
    SlotCurrentIndexChange(0);
}

Widget2::~Widget2()
{
    delete ui;
}

void Widget2::clearWidgetData()
{
    ui->lineEdit->clear();
    ui->comboBox->setCurrentIndex(0);
    ui->comboBox_2->setCurrentIndex(0);
    ui->comboBox_3->setCurrentIndex(0);
}

QStringList Widget2::getwidgetData()
{
    QStringList _list;
    _list.append(ui->lineEdit->text());
    _list.append(ui->dateEdit->date().toString("yyyy-MM"));
    _list.append(ui->comboBox->currentText());
    _list.append(ui->comboBox_2->currentText());
    _list.append(ui->dateEdit_2->date().toString("yyyy-MM-dd"));
    _list.append(ui->comboBox_3->currentText());
    _list.append(ui->comboBox_4->currentText());
    return _list;
}

void Widget2::on_btnQR_clicked()
{
    emit signalNextPage();
}

void Widget2::SlotCurrentIndexChange(int index)
{
    ui->comboBox_4->clear();
    for (auto item : zhibu.at(index).second)
    {
        ui->comboBox_4->addItem(item);
    }
}
